#pragma once
#include <sstream>

namespace bs
{
#define SAFE_DELETE(p)       if(p) { delete (p); (p) = NULL; }
#define SAFE_DELETE_ARRAY(p) if(p) { delete[] (p); (p) = NULL; }

	template<class _T>
	std::string ToStr(_T t)
	{
		std::stringstream ss;
		ss << t;

		return ss.str();
	}

	template<class _T>
	_T StrTo(const char* str)
	{
		_T t;
		std::stringstream ss;
		ss << str;
		ss >> t;

		return t;
	}

	template<class _T>
	class TPoint
	{
	public:
		_T x;
		_T y;

	public:
		TPoint(_T theX, _T theY) : x(theX), y(theY) {}
		TPoint(const TPoint& thePoint) : x(thePoint.x), y(thePoint.y) {}
		TPoint() : x(0), y(0) {}

		inline bool operator == (const TPoint<_T>& p)
		{
			return ((x==p.x) && (y==p.y));
		}

		inline bool operator != (const TPoint<_T>& p)
		{
			return ((x!=p.x) || (y!=p.y));
		}

		TPoint<_T> operator + (const TPoint<_T>& p) const { return TPoint<_T>(x+p.x, y+p.y); }
		TPoint<_T> operator - (const TPoint<_T>& p) const { return TPoint<_T>(x-p.x, y-p.y); }
		TPoint<_T> operator * (const TPoint<_T>& p) const { return TPoint<_T>(x*p.x, y*p.y); }
		TPoint<_T> operator / (const TPoint<_T>& p) const { return TPoint<_T>(x/p.x, y/p.y); }
		TPoint<_T>& operator += (const TPoint<_T>& p)  { x+=p.x; y+=p.y; return *this; }
		TPoint<_T>& operator -= (const TPoint<_T>& p)  { x-=p.x; y-=p.y; return *this; }
		TPoint<_T>& operator *= (const TPoint<_T>& p)  { x*=p.x; y*=p.y; return *this; }
		TPoint<_T>& operator /= (const TPoint<_T>& p)  { x/=p.x; y/=p.y; return *this; }

		operator POINT() { POINT pt = {x, y}; return pt; }
	};

	typedef TPoint<int> Point;
	typedef TPoint<float> FPoint;
}